package si.unimb.src.wifisms.entity;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 
 * @author Ales
 * 
 * Nosilec podatkov za SMS sporocilo.
 * Implementiran vmesnik Serializable (zaradi serializacije na disk).
 *
 */
public class SMSMessage implements Serializable {

	private static final long serialVersionUID = 8254958530129875088L;

	// Iz katerega racuna bomo poslali
	private Account account;
	
	// AuthToken -> to se bo generiralo ob shranjevanju
	private AuthToken authToken = null;
	
	// Prejemniki in vsebina sporocila
	private ArrayList<String> recipients = new ArrayList<String>();
	private String message;
	
	// Mozni statusi
	public static final byte STATUS_WAITING = 0; // caka na posiljanje
	public static final byte STATUS_VALIDATING_TOKEN = 1; // caka na potrditev AuthTokena
	public static final byte STATUS_SENDING = 2; // posiljanje
	public static final byte STATUS_SENT = 3; // poslano
	public static final byte STATUS_FAILED = -1; // napaka pri posiljanju
	
	// Fail message (da vemo kaj je narobe)
	private String failMessage = "neznana napaka";
	
	// Status sporocila
	private byte status = STATUS_WAITING;
	
	/**
	 * 
	 * Privzeti konstruktor
	 * 
	 */
	public SMSMessage() { }
	
	/* GETTERS / SETTERS */
	public Account getAccount() {
		return account;
	}
	
	public void setAccount(Account account) {
		this.account = account;
	}
	
	public ArrayList<String> getRecipients() {
		return recipients;
	}
	
	public void setRecipients(ArrayList<String> recipients) {
		this.recipients = recipients;
	}
	
	public String getMessage() {
		return message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}

	public AuthToken getAuthToken() {
		return authToken;
	}

	public AuthToken createAuthToken() throws InvalidTokenException {
		authToken = account.getAuthToken();
		return authToken;
	}

	public void setStatus(byte status) {
		this.status = status;
	}
	
	public void setFailed(String error) {
	
		this.status = SMSMessage.STATUS_FAILED;
		this.failMessage = error;
		
	}

	public byte getStatus() {
		return status;
	}
	
	public String getStatusString() {
	
		switch(status) {
		
			case SMSMessage.STATUS_WAITING: return "Čaka na pošiljanje";
			case SMSMessage.STATUS_VALIDATING_TOKEN: return "Preverjanje uporabniškega imena in gesla";
			case SMSMessage.STATUS_SENDING: return "Pošiljanje...";
			case SMSMessage.STATUS_SENT: return "Poslano";
			case SMSMessage.STATUS_FAILED: return "Napaka: " + failMessage;
			default: return "Neznan";
		
		}
		
	}
	
}
